package quartz.job;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.quartz.TriggerKey;

public class FirstJob implements Job{
	
	private String setter;
	
	public void setSetter(String setter) {
		this.setter = setter;
	}
	public void execute(JobExecutionContext context) throws JobExecutionException {
		
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh-mm-ss");
		System.out.println(sdf.format(date)+"立即执行，间隔两秒，直到永远");
		//获取参数
		//1、jobDetail
		JobKey jobKey = context.getJobDetail().getKey();
		System.out.println(jobKey.getGroup());
		System.out.println(jobKey.getName());
		System.out.println(jobKey.getClass().getName());
		JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
		System.out.println(jobDataMap.get("hello"));
		//2、trigger
		TriggerKey triggerKey = context.getTrigger().getKey();
		System.out.println(triggerKey.getGroup());
		System.out.println(triggerKey.getName());
		JobDataMap tJobDataMap = context.getTrigger().getJobDataMap();
		System.out.println(tJobDataMap.get("hello"));
		//3、合并,将jobDetail和trigger中的合并，若key相同，则trigger的值会覆盖jobDetail的值
		JobDataMap mergedJobDataMap = context.getMergedJobDataMap();
		System.out.println(mergedJobDataMap.get("hello"));
		
		System.out.println(setter);
		
	}

}
